package pers.cyril.jdb.client;

import com.beust.jcommander.JCommander;
import pers.cyril.jdb.client.command.ConnectCommand;
import pers.cyril.jdb.client.netty.NettyClient;

import java.io.IOException;
import java.util.Properties;

/**
 * 说点什么吧
 *
 * @author Wang Cyril
 * @date 2024/5/20 11:39
 */
public class JDBClient {

    public static void main(String[] args) throws IOException {
        ConnectCommand connectCommand = new ConnectCommand();
        JCommander jc = JCommander.newBuilder()
                .programName("jdb")
                .addCommand(connectCommand).build();
        jc.parse(args);

        if (jc.getParsedCommand() == null) {
            jc.usage();
            return;
        }

        if ("connect".equals(jc.getParsedCommand())) {
            NettyClient client = null;
            if (connectCommand.getUsername() != null && connectCommand.getPassword() != null) {
                client = new NettyClient(connectCommand.getHost(), connectCommand.getPort(), connectCommand.getUsername(), connectCommand.getPassword(), 3);
            } else {
                client = new NettyClient(connectCommand.getHost(), connectCommand.getPort(), 3);
            }
            client.start();
        }


    }

    private static String getProjectVersion() throws IOException {
        Properties properties = new Properties();
        properties.load(JDBClient.class.getClassLoader().getResourceAsStream("app.properties"));
        return properties.getProperty("project.version");
    }
}
